import java.sql.SQLOutput;
import java.util.Random;
import java.util.Scanner;

public class Demo01 {
//    求阶乘和
    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }

    public static int fac(int i) {
        int ret = 1;
        for (int j = 1; j <= i; j++) {
            ret *= j;
        }
        return ret;
    }
//    public static void main(String[] args) {
//        int result = facSum(5);
//        System.out.println(result);
//    }
    public static int add(int x,int y){
        return x+y;
    }
    public static void main16(String[] args) {
        System.out.println(add(3, 4));
    }


    public static void main15(String[] args) {
//        写一个函数返回参数二进制中的个数
        int n = 8;
        int count = 0;
        while(n != 0){
            n = n & (n-1);
            count++;
        }
        System.out.println(count);
    }

    public static void main14(String[] args) {
//        求水仙花数
//        1.先求当前有几位数
//        2.当前数字的每一位
        for (int i = 0; i < 999999; i++) {
            int count = 0;
            int tmp = i;
            while(i != 0){
                count++;
                tmp /= 10;
            }
            tmp = i;

            while (tmp != 0){
//                Math.pow();
            }
        }
    }
    public static void main13(String[] args) {
//        两个整数的最大公约数
//        能够整除一个整数的整数称为其的约数（如5是10约数）
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = a%b;
        while(c!=0){
            a = b;
            b = c;
            c = a%b;
        }
        System.out.println(b);
    }
    public static void main12(String[] args) {
//        9*9乘法表
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+"*"+i+"="+(i*j)+" ");
            }
            System.out.println();
        }
    }
    public static void main11(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int age = scanner.nextInt();
        if (age < 18 ){
            System.out.println("少年");
        } else if (age >= 19 && age <= 28) {
            System.out.println("青年");
        }else if (age <= 55 && age >= 29){
            System.out.println("中年");
        } else if (age >= 56) {
            System.out.println("老年");
        }
    }
    public static void main10(String[] args) {
//        猜数字游戏
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int randNum = random.nextInt(100);
        while(true){
            System.out.println("请输入你要校验的数字：");
            int num = scanner.nextInt();
            if (num == randNum){
                System.out.println("猜对了！");
                break;
            } else if (num < randNum) {
                System.out.println("猜小了");
            } else if (num > randNum) {
                System.out.println("猜大了");
            }
        }
    }
    public static void main9(String[] args) {
//        循环输入
        Scanner scanner = new Scanner(System.in);
//        while (scanner != null){
////            int a = scanner.nextInt();
////            System.out.println(a);
//            String name = scanner.nextLine();
//            System.out.println(name);
//        }
        while(scanner.hasNextLine()){
            String name = scanner.nextLine();
            System.out.println(name);
        }
    }
    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的名字：");
//        scanner.nextLine();读取一行
//        遇到空格会结束
        String name = scanner.next();
        System.out.println(name);

        System.out.println("请输入你的年龄：");
        int age = scanner.nextInt();
        System.out.println(age);

        System.out.println("请输入你的体重：");
        float weight = scanner.nextFloat();
        System.out.println(weight);

//        建议通过close来关闭资源
        scanner.close();
    }
    public static void main7(String[] args) {
        System.out.println("输出且换行");
        System.out.print("输出不换行");
        System.out.printf("%s\n"," 格式化输出！");
    }
    public static void main6(String[] args) {
//        1!+2!+3!+.....+n!
        int n = 5;
        int sum = 0;
        for (int j = 1; j <= n ; j++) {
            int ret = 1;
            for (int i = 1; i <= j; i++) {
                ret *= i;
            }
            sum += ret;
        }
        System.out.println(sum);
    }
    public static void main5(String[] args) {
//        n!
        int n = 5;
        int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
        }
        System.out.println(ret);
    }
    public static void main4(String[] args) {
//        找到1-100之间既能被3整除也能被5整除的数字，要求使用break或者continue
        int i = 1;
//        while(i <= 100){
//            if (i % 5 == 0 && i % 3 == 0){
//                System.out.println(i);
//            }
//            i++;
//        }
        while (i <= 100){
            if (i % 15 != 0){
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }
    public static void main3(String[] args) {
        int i = 0;
        while(i <= 10){
            i++;
            if (i == 2){
                i++;
//                结束循环
//                break;
//                结束本躺循环
                continue;
            }
            System.out.println(i);
//            i++;
        }
    }

    public static void main2(String[] args) {
//        1-100所有整数中出现了多少个数字
        int i = 1;
        int count = 0;
        while(i <= 100){
            if (i % 10 == 9){
                count++;
            } else if (i/10 == 9) {
                count++;
            }
            i++;
        }
        System.out.println(count);
    }
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int k = 0;
        while(k <x ){
            int i = 2;
            while (i <= Math.sqrt(x)){
                if (x % i == 0){
                    System.out.println(x+"不是素数！");
                    break;
                }
                i++;
            }
            System.out.println(x+"是素数");
            k++;
        }
    }
}
